/*
 * Copyright notice
 */

package com.gtd.util


import java.security.MessageDigest
import java.security.NoSuchAlgorithmException

import com.gtd.lib.BASE64Encoder

/**
 * Utility for encrypting password
 * @author hoatle
 *         hoatlevan at gmail dot com
 * @since  1.0
 * @since  Jul 13, 2009
 */
class CryptoUtil {
  public static String encrypt(String x){
    String hash = "";
    try {
      MessageDigest md = null;
      md = MessageDigest.getInstance("SHA-1");
      md.reset();
      md.update(x.getBytes("UTF-8"));
      byte[] raw = md.digest();
      hash = BASE64Encoder.encode(raw).toString();
    } catch (UnsupportedEncodingException ex) {
      //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
      //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    return hash;
  }
}

